package com.reading_recognition_system.controller;

import com.reading_recognition_system.pojo.Error;
import com.reading_recognition_system.service.impl.ErrorServiceImpl;
import com.reading_recognition_system.util.Result;
import com.reading_recognition_system.util.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/error")
public class ErrorController {
    @Autowired
    private ErrorServiceImpl errorService;

    @RequestMapping("/findallerror")
    @ResponseBody
    public Result<List<Error>> findallerror(){
        List<Error> res = errorService.findAllError();
        return new Result<>(StatusCode.SUCCESS, res, "成功");
    }

    @RequestMapping("/deleteallerror")
    @ResponseBody
    public  Result<String> deleteallerror(){
        if (errorService.deleteAllError() != 0 ){
            return new Result<>(StatusCode.SUCCESS, "删除成功", "成功");
        }else {
            return new Result<>(StatusCode.EXCEPTION, "删除失败", "失败");
        }
    }

    @RequestMapping("/deleteoneerror")
    @ResponseBody
    public  Result<String> deleteoneerror(int e_id){
        if (errorService.deleteOneError(e_id) != 0 ){
            return new Result<>(StatusCode.SUCCESS, "删除成功", "成功");
        }else {
            return new Result<>(StatusCode.EXCEPTION, "删除失败", "失败");
        }
    }

    @RequestMapping("/inserterror")
    @ResponseBody
    public  Result<String> inserterror(@RequestBody Error error){
        if (errorService.insertError(error) != 0 ){
            return new Result<>(StatusCode.SUCCESS, "插入成功", "成功");
        }else {
            return new Result<>(StatusCode.EXCEPTION, "插入失败", "失败");
        }
    }
}
